@extends('layouts.app')
@section('content')
    <div class="breadcrumbs ace-save-state" id="breadcrumbs">
        <ul class="breadcrumb">
            <li>
                <i class="ace-icon fa fa-users"></i>
                <a href="{{url('user')}}">管理员管理</a>
            </li>
            <li class="active">行为列表</li>
        </ul><!-- /.breadcrumb -->
    </div>
    <div class="page-content" id="content">
        <div class="page-header">
            <h1>
                行为列表
                <small>
                    <i class="ace-icon fa fa-angle-double-right"></i>
                    后台操作行为
                </small>
            </h1>
        </div><!-- /.page-header -->
        <div class="row">
            <div class="col-md-12">
                <el-button type="primary" @click="dialogFormVisible = true">添加行为</el-button>
            </div>
        </div>
        <div class="row">
            <div class="col-xs-12">
                <table class="table table-striped table-bordered table-hover no-border-top">
                    <tr>
                        <th>行为名称</th>
                        <th>行为说明</th>
                        <th>添加时间</th>
                    </tr>
                    @if($list->isEmpty())
                        <tr>
                            <td colspan="4" class="center">暂无数据</td>
                        </tr>
                    @else
                        @foreach($list as $item)
                            <tr>
                                <td>{{$item->name}}</td>
                                <td>{{$item->action}}</td>
                                <td>{{$item->created_at}}</td>
                            </tr>
                        @endforeach
                    @endif

                </table>
            </div>
        </div>
        @include('layouts.page')
        <el-dialog title="收货地址" :visible.sync="dialogFormVisible" width="30%">
            <el-form :model="form">
                <el-form-item label="行为名称:" :label-width="formLabelWidth">
                    <el-input v-model="form.name" autocomplete="off" clearable autofocus></el-input>
                </el-form-item>
                <el-form-item label="行为说明:" :label-width="formLabelWidth">
                    <el-input v-model="form.action" autocomplete="off" clearable></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="addPermission">确 定</el-button>
            </div>
        </el-dialog>
    </div>
@endsection
@section('js')
    <script type="text/javascript">
        const app = new Vue({
            el: '#content',
            data: {
                dialogFormVisible: false,
                form: {
                    name: '',
                    action: '',
                },
                formLabelWidth: '100px'
            },
            methods: {
                addPermission(){
                    const me = this;
                    let name = this.form.name.trim();
                    let action = this.form.action.trim();
                    if (name.length === 0 || action.length === 0){
                        this.$message.error('行为名称和行为地址必填')
                    }
                    $.post("{{route('addPermission')}}",{name:name,action:action}, function (res) {
                        console.log(res);
                        if (res.state === 'success') {
                            me.$message({
                                showClose: true,
                                message: res.message,
                                type: 'success',
                                onClose(){
                                    window.location.reload()
                                }
                            })
                        }else{
                            me.$message.error(res.message)
                        }
                    })
                }
            }
        })
    </script>
@endsection